package com.scalar.forecast.projectSetup.actionCommands;

import java.util.HashMap;
import java.util.LinkedList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.forecast.actionCommands.ActionCommand;
import com.scalar.forecast.commons.SessionKeys;
import com.scalar.forecast.projectSetup.dao.ProjectSetupDAO;

/**
 * Processes the request to view the Project Forecast details
 *
 * Created by Sujan.
 * Date: oct 10, 2005
 * Time: 7:27:12 PM
 */
public class ProjectSetupProjectForecastViewCommand extends ActionCommand{

    public ActionForward execute( ActionMapping mapping,
                                  ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response ) {

        ActionForward actionForward = mapping.findForward( "viewProjectForecastDetails" );

        int projectId = 0;
        HashMap errors = new HashMap ();
        request.setAttribute( SessionKeys.ERROR_MESSAGES, errors );
        if ( request.getParameter("projectID") != null )
        {
            try
            {
                projectId = Integer.parseInt( request.getParameter("projectID").trim() );
                LinkedList rowDataList = ProjectSetupDAO.loadProjectForecastDetails ( null, projectId );
                request.setAttribute( "rowDataList", rowDataList);
            }
            catch ( Exception e )
            {
                e.printStackTrace();
                errors.put( "Error while loading the Project Forecast details", null );
                actionForward = mapping.findForward( "viewProjectForecastDetails" );
            }
        }
        return actionForward;
    }
}
